package fun.coding.leetcode;

public class SymmetricTree {

	public static void main(String[] args) {
	}
	
	public boolean isSymmetric(TreeNode root) {
		if (root == null) return true;
		
		return helper(root.left, root.right);
	}
	
	public boolean helper(TreeNode l, TreeNode r) {
		if (l == null && r == null) {
			return true;
		} else if (l == null && r != null) {
			return false;
		} else if (l != null && r == null) {
			return false;
		} else {
			if (l.val != r.val) return false;
			
			return helper(l.left, r.right) && helper(l.right, r.left);
		}
	}

}
